package com.manager.service.impl;

import com.manager.bean.PageInfo;
import com.manager.bean.StudentDormitoryExample;
import com.manager.bean.StudentDormitoryKey;
import com.manager.mapper.StudentDormitoryMapper;
import com.manager.service.StudentDormitoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Studentdormitory)表服务实现类
 *
 * @author makejava
 * @since 2021-03-02 11:00:25
 */
@Service("studentdormitoryService")
public class StudentDormitoryServiceImpl implements StudentDormitoryService {
    @Resource
    private StudentDormitoryMapper studentdormitoryDao;

    @Override
    public PageInfo<StudentDormitoryKey> findPageInfo(Integer studentId, Integer dormitoryId, Integer pageIndex, Integer pageSize) {
        return null;
    }

    /**
     * 通过ID查询单条数据
     *
     * @param studentId 主键
     * @return 实例对象
     */
    @Override
    public StudentDormitoryKey queryById(Integer studentId) {
        StudentDormitoryExample studentDormitoryExample = new StudentDormitoryExample();
        StudentDormitoryExample.Criteria criteria = studentDormitoryExample.createCriteria();
        criteria.andStudentIdEqualTo(studentId);
        List<StudentDormitoryKey> studentDormitoryKeys = studentdormitoryDao.selectByExample(studentDormitoryExample);
        if(studentDormitoryKeys.size()==0){
            return null;
        }
        else{
            return studentDormitoryKeys.get(0);
        }
    }

    //获取所有
    @Override
    public List<StudentDormitoryKey> getAll() {
        StudentDormitoryExample studentDormitoryExample = new StudentDormitoryExample();
        StudentDormitoryExample.Criteria criteria = studentDormitoryExample.createCriteria();
        return studentdormitoryDao.selectByExample(studentDormitoryExample);
    }

    /**
     * 新增数据
     *
     * @param studentdormitory 实例对象
     * @return 实例对象
     */
    @Override
    public StudentDormitoryKey insert(StudentDormitoryKey studentdormitory) {
        this.studentdormitoryDao.insert(studentdormitory);
        return studentdormitory;
    }

    /**
     * 修改数据
     *
     * @param studentdormitory 实例对象
     * @return 实例对象
     */
    @Override
    public StudentDormitoryKey update(StudentDormitoryKey studentdormitory) {
        StudentDormitoryExample studentDormitoryExample = new StudentDormitoryExample();
        StudentDormitoryExample.Criteria criteria = studentDormitoryExample.createCriteria();
        int i = this.studentdormitoryDao.updateByExample(studentdormitory, studentDormitoryExample);
        return new StudentDormitoryKey();
    }

    /**
     * 通过主键删除数据
     *
     * @param studentId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer studentId) {
        StudentDormitoryExample studentDormitoryExample = new StudentDormitoryExample();
        StudentDormitoryExample.Criteria criteria = studentDormitoryExample.createCriteria();
        criteria.andStudentIdEqualTo(studentId);
        studentdormitoryDao.deleteByExample(studentDormitoryExample);
        return true;
    }
}
